#include <iostream>
#include <string>
using namespace std;

class Employee
{ // 员工类,基类
//protected:
private:
    string name;       // 姓名
    int age;           // 工龄
    double basesalary; // 基本工资
    double salary;     // 工资

public:
    Employee(string name, int age, double basesalary) : name(name), age(age), basesalary(basesalary) {}
    virtual void CalculateSalary(int days) { salary = basesalary + 100 * days + 100 * age; } // 计算工资函数，使用虚函数关键字，方便重写
    double GetSalary() { return salary; } // 获取工资函数
};

class HR : public Employee
{ // HR类,派生类
private:
    int recruits; // 招聘人数
public:
    HR(string name, int age, double salary) : Employee(name, age, salary), recruits(recruits) {} // 初始化构造函数，调用基类构造函数需要传参
    void CalculateSalary(int recruits)                                                           // 重写父类函数，计算HR的工资
    {
        salary = basesalary + 1000 * recruits + 100 * age;
    }
};

class Manager : public Employee
{ // 经理类,派生类
private:
    int projects; // 项目数
public:
    Manager(string name, int age, double salary) : Employee(name, age, salary), projects(projects) {} // 初始化构造函数，调用基类构造函数需要传参
    void CalculateSalary(int projects)                                                                // 重写父类函数，计算经理的工资
    {
        salary = basesalary + 10000 * projects + 100 * age;
    }
};

class Programmer : public Employee
{ // 程序员类,派生类
private:
    int codeLines; // 项目数
public:
    Programmer(string name, int age, double salary) : Employee(name, age, salary), codeLines(codeLines) {} // 初始化构造函数，调用基类构造函数需要传参
    void CalculateSalary(int codeLines)                                                                    // 重写父类函数，计算程序员的工资
    {
        salary = basesalary + codeLines + 100 * age;
    }
};

int
main()
{
    HR hr("yang", 5, 3000); // 创建HR对象
    Manager manger("sun", 10, 5000); // 创建经理对象
    Programmer programmer("li", 8, 3000); // 创建程序员对象

    hr.CalculateSalary(10); // 计算HR的工资
    manger.CalculateSalary(5); // 计算经理的工资
    programmer.CalculateSalary(3000); // 计算程序员的工资

    cout << "HR的工资：" << hr.GetSalary() << endl; // 输出HR的工资
    cout << "经理的工资：" << manger.GetSalary() << endl; // 输出经理的工资
    cout << "程序员的工资：" << programmer.GetSalary() << endl; // 输出程序员的工资

    //通过基类指针指向，输出薪水
    Employee *eptr = &hr;
    cout << "HR的工资：" << eptr->GetSalary() << endl; // 输出员工的工资
    
    eptr = &manger;
    cout << "经理的工资：" << eptr->GetSalary() << endl; // 输出员工的工资
    eptr = &programmer;
    cout << "程序员的工资：" << eptr->GetSalary() << endl; // 输出员工的工资
    return 0;
}
